//
//  TableViewController.m
//  Tableview
//
//  Created by wang doublejie on 12-4-8.
//  Copyright (c) 2012年 东王. All rights reserved.
//

#import "ShoppingCartViewController.h"
#import "MobClick.h"
#import "Constants.h"
#import "UserConnectionInfoViewController.h"

@interface ShoppingCartViewController ()

@end

@implementation ShoppingCartViewController
@synthesize tableView;
@synthesize dishObjectsDic;
@synthesize shopIdsAry;
@synthesize sumPrice;
@synthesize imageView;
@synthesize everyShopPrice;
@synthesize leftButton;

//加载指示器
-(void)showHUD{
    MBProgressHUD *HUD = [[MBProgressHUD alloc] initWithView:self.navigationController.view];
	[self.navigationController.view addSubview:HUD];
	HUD.dimBackground = YES;
    HUD.delegate = self;
    [HUD showWhileExecuting:@selector(myTask) onTarget:self withObject:nil animated:YES];
}

- (void)myTask {
    [imageView removeFromSuperview];
    //设置清空按钮为可见
    leftButton.hidden = NO;
    FMDBDishManager *fmdbDishManager = [[FMDBDishManager alloc] init];
    NSArray *shopInfoArray = [fmdbDishManager getShopInfo];
    shopIdsAry = [[NSMutableArray alloc] init];
    dishObjectsDic = [[NSMutableDictionary alloc] init];
    sumPrice = 0;//计算总价
    float shopPrice = 0;//计算每家店的价格
    everyShopPrice = [[NSMutableDictionary alloc] init];
    for(NSDictionary *shopInfoDic in shopInfoArray){
        [shopIdsAry addObject:[shopInfoDic objectForKey:@"shopId"]];
        NSMutableArray *dishInfoArray = [fmdbDishManager getDishInfoByShopId:[[shopInfoDic objectForKey:@"shopId"] intValue]];
        [dishObjectsDic setObject:dishInfoArray forKey:[shopInfoDic objectForKey:@"shopId"]];
        //计算总价格
        for(NSDictionary *dishDic in dishInfoArray){
            sumPrice = sumPrice + [[dishDic objectForKey:@"dishPrice"] floatValue] * [[dishDic objectForKey:@"dishNumber"] intValue];
            shopPrice = shopPrice + [[dishDic objectForKey:@"dishPrice"] floatValue] * [[dishDic objectForKey:@"dishNumber"] intValue];
        }
        [everyShopPrice setObject:[[NSString alloc] initWithFormat:@"%f",shopPrice] forKey:[shopInfoDic objectForKey:@"shopId"]];
        shopPrice = 0;
    }
    [tableView reloadData];
    //如果购物车为空时，则显示下面生成的view
    if([shopIdsAry count] == 0){
        //隐藏清空按钮
        leftButton.hidden = YES;
        imageView= [[UIImageView alloc] initWithFrame:CGRectMake(0.0, 0.0, 320, 480)];
        [imageView setBackgroundColor:[UIColor whiteColor]];
        //购物车图片背景
        UIImageView *bgImage = [[UIImageView alloc] initWithFrame:CGRectMake(97.5, 80.0, 125, 125)];
        NSString *filePath=[[NSBundle mainBundle] pathForResource:@"nullshop" ofType:@"png"];
        [bgImage setImage:[UIImage imageWithContentsOfFile:filePath]];
        //文字描述
        UILabel *descLabel = [[UILabel alloc] initWithFrame:CGRectMake(80, 215, 150, 30)];
        descLabel.font = [UIFont fontWithName:@"Helvetica-Bold" size:14];
        [descLabel setText:@"您的购物车是空的"];
        descLabel.textAlignment = UITextAlignmentCenter;
        descLabel.textColor = [UIColor orangeColor];
        
        [imageView addSubview:bgImage];
        [imageView addSubview:descLabel];
        [self.view addSubview:imageView];
    }
}

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}

- (void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:NO];
    
    [self showHUD];
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    //设置视图title
    self.title=@"购物车";
    tableView=[[UITableView alloc]initWithFrame:CGRectMake(0, 0, 320, SSiphoneType == 0 ? 370 : 458)];
    [tableView setDelegate:self];
    [tableView setDataSource:self];
    [tableView setSeparatorStyle:UITableViewCellSeparatorStyleNone];//去掉cell之间的分割线
    [tableView setBackgroundColor:[UIColor clearColor]];
    UIImageView *background = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"shoppingCartBg.png"]];
    [background setFrame:CGRectMake(0, 0, 320, SSiphoneType == 0 ? 370 : 458)];
    
    [self.view addSubview:background];
    [self.view addSubview:tableView];
    
    leftButton = [[UIButton alloc] initWithFrame:CGRectMake(0,0,46,27)];
    [leftButton setBackgroundImage:[UIImage imageNamed:@"cancelBtnBg.png"] forState:UIControlStateNormal];
    [leftButton setTitle:@"清 空" forState:UIControlStateNormal];
    leftButton.titleLabel.font=[UIFont fontWithName:@"Helvetica-Bold" size:14];
    [leftButton addTarget:self action:@selector(clearAll) forControlEvents:UIControlEventTouchUpInside];
    UIBarButtonItem *leftItem = [[UIBarButtonItem alloc] initWithCustomView:leftButton];
    //设置为左边按钮
    [[self navigationItem] setLeftBarButtonItem:leftItem];
}

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{ 
    //* 出现几组
    if([shopIdsAry count] > 0){
        return [shopIdsAry count]+2;
    }
    else{
        return 0;
    }
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    if(section < [shopIdsAry count]){
        NSInteger i =  [[dishObjectsDic objectForKey:[shopIdsAry objectAtIndex:section]] count];
        return i + 1;
    }
    else{
        return 0;
    }
}

- (UITableViewCell *)tableView:(UITableView *)tableview
         cellForRowAtIndexPath:(NSIndexPath *)indexPath { 
    static NSString *identifier = @"TypeIdentifier";
    UITableViewCell *cell=[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:identifier];
    //设置cell的背景颜色
    cell.contentView.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"bg3.png"]];
    NSUInteger row = [indexPath row];
    NSUInteger sectionMy = [indexPath section];
    if(row < [[dishObjectsDic objectForKey:[shopIdsAry objectAtIndex:sectionMy]] count]){
        //生成显示菜名的label
        UILabel *dishNameLab = [[UILabel alloc] initWithFrame:CGRectMake(10, 0, 150, 45)];
        dishNameLab.font = [UIFont fontWithName:@"Helvetica-Bold" size:14];
        dishNameLab.text = [[[dishObjectsDic objectForKey:[shopIdsAry objectAtIndex:sectionMy]] objectAtIndex:row] objectForKey:@"dishName"];
        dishNameLab.textColor = [UIColor whiteColor];
        dishNameLab.backgroundColor=[UIColor clearColor];
        
        //生成显示单价的label
        UILabel *dishPriceLab = [[UILabel alloc] initWithFrame:CGRectMake(170, 0, 50, 45)];
        dishPriceLab.font = [UIFont fontWithName:@"Helvetica-Bold" size:14];
        float dishPrice = [[[[dishObjectsDic objectForKey:[shopIdsAry objectAtIndex:sectionMy]] objectAtIndex:row] objectForKey:@"dishPrice"] floatValue];
        if(dishPrice != 0){
            dishPriceLab.text = [[NSString alloc] initWithFormat:@"￥%0.2f",dishPrice];
        }
        else{
            dishPriceLab.text = @"时价";
        }
        dishPriceLab.textColor = [UIColor whiteColor];
        dishPriceLab.backgroundColor=[UIColor clearColor];
        
        //定义减少按钮
        UIButton *minusButton = [[UIButton alloc] initWithFrame:CGRectMake(235, 10, 25, 25)];
        NSString *filePath2=[[NSBundle mainBundle] pathForResource:@"minus" ofType:@"png"];
        [minusButton setBackgroundImage:[UIImage imageWithContentsOfFile:filePath2] forState:UIControlStateNormal];
        [minusButton addTarget:self action:@selector(minuButtonPressd:) forControlEvents:UIControlEventTouchUpInside];
        minusButton.tag = [[[[dishObjectsDic objectForKey:[shopIdsAry objectAtIndex:sectionMy]] objectAtIndex:row] objectForKey:@"dishId"] intValue];
        minusButton.titleLabel.text = [[NSString alloc] initWithFormat:@"%d",indexPath.section];//存放用户点击的按钮所在的section
        minusButton.titleLabel.hidden = YES;
        minusButton.titleLabel.tag = indexPath.row;//存放用户点击按钮所在行
        
        //定义增加按钮
        UIButton *addButton = [[UIButton alloc] initWithFrame:CGRectMake(287, 10, 25, 25)];
        NSString *filePath3=[[NSBundle mainBundle] pathForResource:@"add" ofType:@"png"];
        [addButton setBackgroundImage:[UIImage imageWithContentsOfFile:filePath3] forState:UIControlStateNormal];
        [addButton addTarget:self action:@selector(addButtonPressd:) forControlEvents:UIControlEventTouchUpInside];
        addButton.tag = [[[[dishObjectsDic objectForKey:[shopIdsAry objectAtIndex:sectionMy]] objectAtIndex:row] objectForKey:@"dishId"] intValue];
        addButton.titleLabel.text = [[NSString alloc] initWithFormat:@"%d",indexPath.section];//存放用户点击的按钮所在的section
        addButton.titleLabel.hidden = YES;
        addButton.titleLabel.tag = indexPath.row;//存放用户点击按钮所在行
        
        //定义显示数字的label
        UILabel *countLab = [[UILabel alloc] initWithFrame:CGRectMake(223, 0, 100, 45)];
        countLab.font = [UIFont fontWithName:@"Helvetica-Bold" size:14];
        NSInteger dishNumber = [[[[dishObjectsDic objectForKey:[shopIdsAry objectAtIndex:sectionMy]] objectAtIndex:row] objectForKey:@"dishNumber"] intValue];
        countLab.text = [[NSString alloc] initWithFormat:@"%d",dishNumber];
        countLab.textAlignment = UITextAlignmentCenter;
        countLab.adjustsFontSizeToFitWidth = YES;
        countLab.textColor = [UIColor whiteColor];
        countLab.backgroundColor=[UIColor clearColor];;
        
        [cell.contentView addSubview:dishNameLab];
        [cell.contentView addSubview:dishPriceLab];
        [cell.contentView addSubview:countLab];
        [cell.contentView addSubview:minusButton];
        [cell.contentView addSubview:addButton];
        //设置cell点击无反应
        [cell setSelectionStyle:UITableViewCellSelectionStyleNone];
    }
    //最后一行定义结算按钮
    else{
        UIButton *checkOutBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        [checkOutBtn setFrame:CGRectMake(12, 0, 300, 50)];
        NSString *filePath2=[[NSBundle mainBundle] pathForResource:@"buttonBg" ofType:@"png"];
        UIImage *buttonImage = [UIImage imageWithContentsOfFile:filePath2];
        [checkOutBtn setBackgroundImage:buttonImage forState:UIControlStateNormal];
        [checkOutBtn setTitle:@"结  算" forState:UIControlStateNormal];
        checkOutBtn.titleLabel.font=[UIFont fontWithName:@"Helvetica-Bold" size:16];
        checkOutBtn.tag = [[shopIdsAry objectAtIndex:sectionMy] intValue];
        [checkOutBtn addTarget:self action:@selector(checkOutAction:) forControlEvents:UIControlEventTouchUpInside];
        [cell.contentView addSubview:checkOutBtn];
    }
    
	return cell;
}

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
    if(section == [shopIdsAry count]+1){
        return 120.0f;
    }
    else{
        return 45.0f;
    }
}

- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
    if ([shopIdsAry count] > 0){
        if(section < [shopIdsAry count]){
            FMDBDishManager *fmdbDishManager = [[FMDBDishManager alloc] init];
            //根据商家ID获取商家的名称和电话
            NSDictionary *shopInfoDic = [fmdbDishManager getShopInfoByDishId:[[shopIdsAry objectAtIndex:section] intValue]];
            
            UIView *headerView= [[UIView alloc] initWithFrame:CGRectMake(0.0, 0.0, 320, 45)];
            headerView.backgroundColor=[UIColor colorWithPatternImage:[UIImage imageNamed:@"bg1.png"]];
            //显示店名的label
            UILabel * headerLabel = [[UILabel alloc] initWithFrame:CGRectZero];
            headerLabel.backgroundColor = [UIColor clearColor];
            headerLabel.opaque = NO;
            headerLabel.textColor = [UIColor whiteColor];
            headerLabel.font = [UIFont boldSystemFontOfSize:18];
            headerLabel.frame = CGRectMake(5.0, 0.0, 180.0, 45.0);
            headerLabel.text = [shopInfoDic objectForKey:@"shopName"];
            //显示小计的label
            UILabel * countPrice = [[UILabel alloc] initWithFrame:CGRectZero];
            countPrice.backgroundColor = [UIColor clearColor];
            countPrice.opaque = NO;
            countPrice.textColor = [UIColor whiteColor];
            countPrice.font = [UIFont boldSystemFontOfSize:12];
            countPrice.frame = CGRectMake(180.0, 0.0, 90.0, 45.0);
            float price = [[everyShopPrice objectForKey:[shopIdsAry objectAtIndex:section]] floatValue];
            countPrice.text = [[NSString alloc] initWithFormat:@"小计：￥%0.2f",price];
            //拨打电话按钮
            UIButton *phoneButton = [UIButton buttonWithType:UIButtonTypeCustom];
            [phoneButton setFrame:CGRectMake(270, 0, 45, 45)];
            NSString *filePath2=[[NSBundle mainBundle] pathForResource:@"phone02" ofType:@"png"];
            UIImage *buttonImage = [UIImage imageWithContentsOfFile:filePath2];
            [phoneButton setBackgroundImage:buttonImage forState:UIControlStateNormal];
            phoneButton.tag = 1;
            phoneButton.titleLabel.text = [shopInfoDic objectForKey:@"phoneNumber"];
            [phoneButton addTarget:self action:@selector(callAction:) forControlEvents:UIControlEventTouchUpInside];
            
            [headerView addSubview:headerLabel];
            [headerView addSubview:countPrice];
            [headerView addSubview:phoneButton];
            return headerView;
        }
        else if(section == [shopIdsAry count]){
            UIView *headerView= [[UIView alloc] initWithFrame:CGRectMake(0.0, 0.0, 320, 45)];
            headerView.backgroundColor=[UIColor colorWithPatternImage:[UIImage imageNamed:@"bg1.png"]];
            UILabel * headerLabel = [[UILabel alloc] initWithFrame:CGRectZero];
            headerLabel.backgroundColor = [UIColor clearColor];
            headerLabel.opaque = NO;
            headerLabel.textColor = [UIColor whiteColor];
            headerLabel.font = [UIFont boldSystemFontOfSize:20];
            headerLabel.frame = CGRectMake(0.0, 0.0, 320.0, 45.0);
            headerLabel.text = [[NSString alloc] initWithFormat:@"总计：￥%0.2f",sumPrice];
            headerLabel.textAlignment = UITextAlignmentCenter;
            [headerView addSubview:headerLabel];
            return headerView;
        }
        else if(section == [shopIdsAry count]+1){
            UIView *headerView= [[UIView alloc] initWithFrame:CGRectMake(0.0, 0.0, 320, 120)];
            headerView.backgroundColor=[UIColor clearColor];
            
            UILabel * legWorkInfo = [[UILabel alloc] initWithFrame:CGRectZero];
            legWorkInfo.backgroundColor = [UIColor clearColor];
            legWorkInfo.opaque = NO;
            legWorkInfo.textColor = [UIColor whiteColor];
            legWorkInfo.font = [UIFont boldSystemFontOfSize:14];
            legWorkInfo.frame = CGRectMake(0.0, 0.0, 320.0, 50.0);
            legWorkInfo.textAlignment = UITextAlignmentCenter;
            legWorkInfo.text = @"亲，小二更快哦！";
            
            UIButton *phoneButton = [UIButton buttonWithType:UIButtonTypeCustom];
            [phoneButton setFrame:CGRectMake(12, 50, 300, 50)];
            NSString *filePath2=[[NSBundle mainBundle] pathForResource:@"buttonBg" ofType:@"png"];
            UIImage *buttonImage = [UIImage imageWithContentsOfFile:filePath2];
            [phoneButton setBackgroundImage:buttonImage forState:UIControlStateNormal];
            [phoneButton setTitle:@"拨打小二电话" forState:UIControlStateNormal];
            phoneButton.titleLabel.font=[UIFont fontWithName:@"Helvetica-Bold" size:16];
            phoneButton.tag = 2;
            [phoneButton addTarget:self action:@selector(callAction:) forControlEvents:UIControlEventTouchUpInside];
            
            [headerView addSubview:legWorkInfo];
            [headerView addSubview:phoneButton];
            return headerView;
        }
    }
    return nil;
}

//选中时执行的操作
- (NSIndexPath *)tableView:(UITableView *)tableView 
  willSelectRowAtIndexPath:(NSIndexPath *)indexPath { 
    
    return indexPath; 
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    //这里控制值的大小
    return 45.0;  //控制行高
    
}

- (void)clearAll{
    UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"提  示" message:@"确定要清空购物车吗？" delegate:self cancelButtonTitle:@"确  定"  otherButtonTitles:@"取  消",nil];
    alert.tag = -1;
    [alert show];
}

- (void)minuButtonPressd:(UIButton *)sender{
    NSURL *system_sound_url=[NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:@"1248" ofType:@"wav"]];
    SystemSoundID system_sound_id;
    AudioServicesCreateSystemSoundID((__bridge CFURLRef)system_sound_url, &system_sound_id);
    AudioServicesPlaySystemSound(system_sound_id);
    
    NSInteger section = [sender.titleLabel.text intValue];//用户点击的按钮所在的section
    NSInteger row = sender.titleLabel.tag;//用户点击按钮所在行
    NSInteger dishId = sender.tag;//当前行菜品的ID
    //获取之前的菜品数量
    NSInteger hisNumber = [[[[dishObjectsDic objectForKey:[shopIdsAry objectAtIndex:section]] objectAtIndex:row] objectForKey:@"dishNumber"] intValue];
    
    if(hisNumber > 1){
        //修改数据库的数据，并刷新页面重新读取
        FMDBDishManager *fmdbDishManager = [[FMDBDishManager alloc] init];
        [fmdbDishManager updateDishNumber:dishId newDishNum:hisNumber-1];
        [self showHUD];
    }
    else{
        UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"提  示" message:@"确定删除该菜品？" delegate:self cancelButtonTitle:@"确  定"  otherButtonTitles:@"取  消",nil];
        alert.tag = dishId;
        [alert show];
    }
}

//定义点击结算按钮时的操作
- (void)checkOutAction:(UIButton *)sender{
    NSURL *system_sound_url=[NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:@"1248" ofType:@"wav"]];
    SystemSoundID system_sound_id;
    AudioServicesCreateSystemSoundID((__bridge CFURLRef)system_sound_url, &system_sound_id);
    AudioServicesPlaySystemSound(system_sound_id);
    
    NSMutableDictionary *dictionary = [[NSMutableDictionary alloc] initWithObjectsAndKeys:[[NSString alloc] initWithFormat:@"%d",sender.tag],@"shopId", nil];
    UserConnectionInfoViewController *userConnectionInfoViewController= [[UserConnectionInfoViewController alloc]init];
    [userConnectionInfoViewController setRecieveDictionary:dictionary];
    
    [self.navigationController pushViewController: userConnectionInfoViewController animated:YES];

}

//定义点击拨号按钮时的操作
- (void)callAction:(UIButton *)sender{
    NSURL *system_sound_url=[NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:@"1248" ofType:@"wav"]];
    SystemSoundID system_sound_id;
    AudioServicesCreateSystemSoundID((__bridge CFURLRef)system_sound_url, &system_sound_id);
    AudioServicesPlaySystemSound(system_sound_id);

    NSString *phoneNumber = [[NSString alloc] init];
    if(sender.tag == 1){
        phoneNumber = sender.titleLabel.text;
    }
    else if(sender.tag == 2){
        phoneNumber = [MobClick getConfigParams:@"legWorkCompanyPhone"];
    }
    NSArray *phoneNumberArray = [phoneNumber componentsSeparatedByString:@","];
    UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"拨打电话" message:@"请选择要拨打的号码" delegate:self cancelButtonTitle:@"取  消" otherButtonTitles:nil];
    [alert dismissWithClickedButtonIndex:0 animated:YES];
    alert.tag = 0;
    for(NSString *phone in phoneNumberArray){
        [alert addButtonWithTitle:phone];
    }
    [alert show];
}

//根据被点击按钮的索引处理点击事件
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex {
    //tag为1时为点击拨号按钮时弹出的对话框
    if(alertView.tag == 0){
        NSString *number = [alertView buttonTitleAtIndex:buttonIndex];
        //phoneNumber为号码字符串
        NSString *phoneNumber = [[NSString alloc] initWithFormat:@"tel://%@",number];
        //拨号
        [[UIApplication sharedApplication] openURL:[NSURL URLWithString:phoneNumber]];
    }
    //清空购物车
    else if(alertView.tag == -1){
        if(buttonIndex == 0){
            FMDBDishManager *fmdbDishManager = [[FMDBDishManager alloc] init];
            [fmdbDishManager clearShoppingCart];
            [self showHUD];
        }
    }
    //询问是否删除菜品的对话框
    else{
        //提示用户是否删除菜品的对话框，当用户点击确定时
        if(buttonIndex == 0){
            FMDBDishManager *fmdbDishManager = [[FMDBDishManager alloc] init];
            [fmdbDishManager deleteDishByDishIdInShoppingCart:alertView.tag];
            [self showHUD];
        }
    }
}

- (void)addButtonPressd:(UIButton *)sender{
    NSURL *system_sound_url=[NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:@"1248" ofType:@"wav"]];
    SystemSoundID system_sound_id;
    AudioServicesCreateSystemSoundID((__bridge CFURLRef)system_sound_url, &system_sound_id);
    AudioServicesPlaySystemSound(system_sound_id);
    
    NSInteger section = [sender.titleLabel.text intValue];//用户点击的按钮所在的section
    NSInteger row = sender.titleLabel.tag;//用户点击按钮所在行
    NSInteger dishId = sender.tag;//当前行菜品的ID
    //获取之前的菜品数量
    NSInteger hisNumber = [[[[dishObjectsDic objectForKey:[shopIdsAry objectAtIndex:section]] objectAtIndex:row] objectForKey:@"dishNumber"] intValue];

    //修改数据库的数据，并刷新页面重新读取
    FMDBDishManager *fmdbDishManager = [[FMDBDishManager alloc] init];
    [fmdbDishManager updateDishNumber:dishId newDishNum:hisNumber+1];
    [self showHUD];
}
- (void)viewDidUnload
{
    self.dishObjectsDic = nil;
    self.shopIdsAry = nil;
    self.tableView = nil;
    self.imageView = nil;
    self.everyShopPrice = nil;
    self.leftButton = nil;
    [super viewDidUnload];
}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    return (interfaceOrientation == UIInterfaceOrientationPortrait);
}

@end
